<template>
  <div class="container">
    <div class="chart" ref="chart"></div>
  </div>
</template>
  
  <script lang="ts" setup>
import { ref, reactive, onMounted } from "vue";
import * as echarts from "echarts";
import { OptionFun as moveOption } from "./ts/map";
const chart = ref<HTMLDivElement | null>(null);
let myChart: any;
const moveData = reactive({
  colorList: ["0, 255, 255", "62, 253, 3", "253, 250, 3"], // 图表色卡
  points: [
    // 节点数据
    { value: [118.8062, 31.9208], itemStyle: { color: "#4ab2e5" } },
    { value: [127.9688, 45.368], itemStyle: { color: "#4fb6d2" } },
    { value: [110.3467, 41.4899], itemStyle: { color: "#52b9c7" } },
    { value: [125.8154, 44.2584], itemStyle: { color: "#5abead" } },
    { value: [116.4551, 40.2539], itemStyle: { color: "#f34e2b" } },
    { value: [123.1238, 42.1216], itemStyle: { color: "#f56321" } },
    { value: [114.4995, 38.1006], itemStyle: { color: "#f56f1c" } },
    { value: [117.4219, 39.4189], itemStyle: { color: "#f58414" } },
    { value: [112.3352, 37.9413], itemStyle: { color: "#f58f0e" } },
    { value: [109.1162, 34.2004], itemStyle: { color: "#f5a305" } },
    { value: [103.5901, 36.3043], itemStyle: { color: "#e7ab0b" } },
    { value: [106.3586, 38.1775], itemStyle: { color: "#dfae10" } },
    { value: [101.4038, 36.8207], itemStyle: { color: "#d5b314" } },
    { value: [103.9526, 30.7617], itemStyle: { color: "#c1bb1f" } },
    { value: [108.384366, 30.439702], itemStyle: { color: "#b9be23" } },
    { value: [113.0823, 28.2568], itemStyle: { color: "#a6c62c" } },
    { value: [102.9199, 25.46639], itemStyle: { color: "#96cc34" } },
    { value: [119.4543, 25.9222] },
  ],
  lines: [
    // 连线数据
    {
      coords: [
        [118.8062, 31.9208],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#4ab2e5" },
    },
    {
      coords: [
        [127.9688, 45.368],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#4fb6d2" },
    },
    {
      coords: [
        [110.3467, 41.4899],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#52b9c7" },
    },
    {
      coords: [
        [125.8154, 44.2584],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#5abead" },
    },
    {
      coords: [
        [116.4551, 40.2539],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#f34e2b" },
    },
    {
      coords: [
        [123.1238, 42.1216],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#f56321" },
    },
    {
      coords: [
        [114.4995, 38.1006],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#f56f1c" },
    },
    {
      coords: [
        [117.4219, 39.4189],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#f58414" },
    },
    {
      coords: [
        [112.3352, 37.9413],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#f58f0e" },
    },
    {
      coords: [
        [109.1162, 34.2004],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#f5a305" },
    },
    {
      coords: [
        [103.5901, 36.3043],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#e7ab0b" },
    },
    {
      coords: [
        [106.3586, 38.1775],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#dfae10" },
    },
    {
      coords: [
        [101.4038, 36.8207],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#d5b314" },
    },
    {
      coords: [
        [103.9526, 30.7617],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#c1bb1f" },
    },
    {
      coords: [
        [108.384366, 30.439702],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#b9be23" },
    },
    {
      coords: [
        [113.0823, 28.2568],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#a6c62c" },
    },
    {
      coords: [
        [102.9199, 25.46639],
        [119.4543, 25.9222],
      ],
      lineStyle: { color: "#96cc34" },
    },
  ],
  name: "自定义数据",
  legendData: ["自定义数据"],
  legendShow: false, // 是否显示图例
  legendSingle: false, // 图例单选or多选
});
function init() {
  if (myChart) {
    myChart.clear();
  }
  myChart = echarts.init(chart.value);
  myChart.setOption(moveOption(moveData)); //设置option
}
onMounted(() => {
  init();
});
</script>
  
  <style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
  .chart {
    width: 100%;
    height: 100%;
  }
}
</style>